package api.homework.two.two;

import java.util.Random;

/**
 * @author lwj
 * @date 2025-03-11
 * @vesion 1.0.0
 */
public class SellingTicketsThread extends Thread{
    @Override
    public void run() {
        // 总票数
        int ticket = 50;
        for(;;){
            int num = new Random().nextInt(10);
            if(num != 0){
                int temp = ticket - num;
                // 判断票数不为0
                if(temp < 0){
                    num = ticket;
                    ticket -= ticket;
                }else{
                    ticket = temp;
                }
                System.out.println("这次卖出了"+num+"张电影票,还剩"+ticket+"张电影票");
            }

            if(ticket == 0){
                System.out.println("票卖完了不好意思！");
                break;
            }
        }
    }
}
